package com.dmgis.qxfw.dataservice.commonservice.dmgis_file_srv.controller;

import com.dmgis.qxfw.dataservice.commonservice.dmgis_file_srv.common.domain.DbConfig;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dataservice")
public class FileRequsetController {

    @RequestMapping("/fileDataService")
    @ResponseBody
    public Object processRequest(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        String collectionName = "";
        String advCode = null;
        CommonsMultipartResolver multipartResolver = null;
        Map<String, Object> updateData = Maps.newHashMap();
        //获取参数名 返回一个枚举类型
        Enumeration<String> em = request.getParameterNames();
        Map<String, Object> sqlMap = Maps.newHashMap();
        String path = "";

        //遍历
        while (em.hasMoreElements()) {
            String name = (String) em.nextElement();
            String value = request.getParameter(name);
            if (!"sqlType".equals(name)) {
                if ("collectionName".equals(name)) {
                    collectionName = value;
                } else if ("advCode".equals(name)) {
                    advCode = value;
                } else {
                    //添加到集合中
                    sqlMap.put(name, value);
                    path += "//" + value;
                }
            }
        }
        if (StringUtils.isBlank(collectionName)) {
            return "collectionName参数不能为空，请确定数据库表名称";
        }
        if (advCode == null)
            path = DbConfig.qxURL + path;
        else
            path = DbConfig.fwURL + path;
        try {
            String sqlType = request.getParameter("sqlType");
            switch (sqlType.toLowerCase()) {
                case "select":

                    break;
                case "insert":
                    break;
                case "update":
                    break;
                case "delete":
                    break;
                case "exist":
                    break;
            }

        } catch (Exception e) {
        }
        return "";
    }
}
